// gamecore.h
#ifndef GAMECORE_H
#define GAMECORE_H

#include <QObject>
#include <QPoint>
#include "mapdata.h"

enum class GameState {
    Ready, Running, Paused, Completed, GameOver
};

enum class Direction { Up, Down, Left, Right };

class GameCore : public QObject {
    Q_OBJECT

public:
    explicit GameCore(QObject *parent = nullptr);

    void initialize(const MapData &mapData);
    void resetLevel();
    bool movePlayer(Direction direction);
    bool checkLevelCompleted() const;

    GameState gameState() const { return m_state; }
    const MapData &currentMap() const { return m_currentMap; }
    QPoint playerPosition() const { return m_playerPos; }

signals:
    void gameStateChanged(GameState newState);
    void mapUpdated();
    void moveCountChanged(int count);

private:
    GameState m_state = GameState::Ready;
    MapData m_originalMap;
    MapData m_currentMap;
    QPoint m_playerPos;
    int m_moveCount = 0;

    bool isValidPosition(int x, int y) const;
    void updateGameState();
    void updatePlayerPosition(int oldX, int oldY, int newX, int newY);
};

#endif // GAMECORE_H
